/**
 * 我的资料
 * author:zhangjlt
 * date:2016年3月10日10:30:42
 */
;
define(function(require, exports, module) {
	var wechat = require("wechat");
	var yuyue = {
		education: [],
		/**
		 * bindEvent 页面事件
		 */
		bindEvent: function() {
			
			$("#yuyue_submit_btn").unbind().on("click", function() {
				var param ={};
				var name =$("#name_yuyue").val();
				if(name &&name.length>0){
					param.name = name;
				}else{
					common.showTip({
						content: "请输入您的名字"
					});
					
				}
				var phone=$("#phone_yuyue").val();
				if(phone &&phone.length>0){
					param.phone = phone;
				}else{
					common.showTip({
						content: "请输入您的电话"
					});
				
				}
				var day=$("#date_yuyue").val();
				if(day &&day.length>0){
					param.day = day;
				}else{
					common.showTip({
						content: "请选择预约日期"
					});
					
				}
				var time =$("#time_yuyue").val();
				if(time &&time.length>0){
					param.time = time;
				}else{
					common.showTip({
						content: "请选择预约时间"
					});
					
				}
				var chang=$("#chang_yuyue").val();
				if(chang &&chang.length>0){
					param.chang = chang;
				}else{
					common.showTip({
						content: "请选择预约场地"
					});
					
				}
				var teacher=$("#teacher_yuyue").val();
				if(teacher &&teacher.length>0){
					param.teacher = teacher;
				}else{
					common.showTip({
						content: "请选择预约教练"
					});
				
				}
				var myDate = new Date();
				var month = myDate.getMonth()+1;
				var day = myDate.getDate();
				var hour = myDate.getHours();
				var min = myDate.getMinutes();
				var str = myDate.getFullYear()+"年"+month+"月"+day+"日"+hour+":"+min;
				param.submitTime =str;
				var paramstr = JSON.stringify(param);
				window.localStorage.setItem("paramstr",paramstr);
				window.location.href = "#/index/completeAppointment";
				
				
			});
			//返回
			$("#return_yuyue").unbind().on("click", function() {
				window.location.href = "#/index/my";
				//window.history.back(-1);
			});
			$("#yuyeu_date_select").unbind().on("click", function() {
				var dtPicker = new mui.DtPicker({
					"type": "date",
					"beginYear": 1949,
					"endYear": 2018
				});
				dtPicker.show(function(selectItems) {

					var str = selectItems.y.text + "年" + selectItems.m.text + "月" + selectItems.d.text + "日";
					$("#date_yuyue").val(str);
					dtPicker.dispose();

				});
			});
			$("#time_select").unbind().on("click", function() {
				var picker = new mui.PopPicker();
				picker.setData([{ value: '1', text: '08:00-10:00' }, { value: '2', text: '10:00-12:00' },{ value: '3', text: '13:00-15:00' },{ value: '4', text: '15:00-17:00' },{ value: '5', text: '18:00-20:00' }]);

				picker.show(function(selectItems) {
					$("#time_yuyue").val(selectItems[0].text);
					
					picker.dispose();
				}, function(selectItems) {
					picker.dispose();
				});
			});
			$("#chang_select").unbind().on("click", function() {
				var picker = new mui.PopPicker();
				picker.setData([{ value: '1', text: '东区第一训练场' }, { value: '2', text: '东区第二训练场' },{ value: '3', text: '东区第三训练场' },{ value: '4', text: '东区第四训练场' },{ value: '5', text: '西区第一训练场' }]);

				picker.show(function(selectItems) {
					$("#chang_yuyue").val(selectItems[0].text);
					
					picker.dispose();
				}, function(selectItems) {
					picker.dispose();
				});
			});
			$("#teacher_select").unbind().on("click", function() {
				var picker = new mui.PopPicker();
				picker.setData([{ value: '1', text: '张教练' }, { value: '2', text: '王教练' },{ value: '3', text: '李教练' },{ value: '4', text: '吕教练' },{ value: '5', text: '刘教练' }]);

				picker.show(function(selectItems) {
					$("#teacher_yuyue").val(selectItems[0].text);
					
					picker.dispose();
				}, function(selectItems) {
					picker.dispose();
				});
			});
		},
		/**
		 * 进行页面路由监听配置
		 */
		bindRout: function() {
			//公共页面监听路由
			Path.map("#/index/:page_name").to(function() {
				console.log(this.params["page_name"]);
				var page_name = this.params["page_name"];
				//来自状态
				var from = "right";
				if(page_name == "my") {
					from = "left";
					//记录状态
					common.loadPage({
						pageUrl: "html/" + page_name + ".html",
						reload: true,
						from: from
					});
				} else {
					//记录状态
					common.loadPage({
						pageUrl: "html/" + page_name + ".html",
						reload: true,
						from: from
					});
				}

			});
			//公共页面监听路由
			Path.map("#home").to(function() {
				//返回首页
				common.loadPage({
					pageUrl: "html/index.html",
					reload: false,
					from: "left"
				});
			});
			//Path.root("#home");
			Path.listen();
		},
		/**
		 * 页面数据加载
		 */
		initData: function() {
			var appid = window.localStorage.getItem("appId");
			var openid = window.localStorage.getItem("openId");
			var param = {
			};
			common.loadData({
				url: "/webchat/getuserinfo?appid=" + appid + "&openid=" + openid, //"/UMPPubServlet?method=getWxUserInfo",
				param: param,
				successCallBack: function(res) {
					if(res.status == "1") {
						$("#name_yuyue").val(res.data.nickname);						
					}else{
						common.showTip({
							content: "获取微信用户信息出错"
						});
					}
				}, //回调函数
				cache: false
			}); 
			var iscroll = require("iscroll");
			common.initIscroll({
				container: "iscrollContent_yuyue",
				showScrollBar: false,
			});
		},
		/**
		 * each page init mothed
		 */
		initialize: function() {
			//动态加载数据
			yuyue.initData();
			//事件绑定
			yuyue.bindEvent();
			//路由绑定
			yuyue.bindRout();
		}
	};

	module.exports = yuyue;
});